

$(function(){
  
    let objs={
        key:"",
        type:"",
        page:1,
        perpage:6
    }
  
    // one--
  function list(){
      if(objs.type!=""){
          objs.key=""
      }
      if(objs.type!=""){
        objs.key=""
    }
    // window.location.href.split("=")[1]
    $.ajax({
        url:"index/search",
        type:"get",
        data:objs,
        success:function (res) {
            console.log(res)
            let temps=template(`one`,res.data)
            $(`.left_con`).html(temps)
            layui.use(`laypage`,function(){
                let laypage=layui.laypage;
               laypage.render({
                elem:"pagination",
                count:res.data.totalCount,
                limit:objs.perpage,
                curr:objs.page,
                jump:function(obj,first){
                    objs.page=obj.curr
                    if(!first){
                       list() 
                    }
                }
               })
            })
            objs.type=""
            objs.key=""
        }
    })
  }

// console.log(window.location.href.indexOf(`+`))
  if(window.location.href.split("=")[1]||window.location.href.split("+")[1]!=undefined){
    
    if(window.location.href.indexOf(`+`)!=`-1`){
        objs.key=window.location.href.split("+")[1]
    }else{
        objs.type=window.location.href.split("=")[1]
    }
   
    list()

}
// let params=new URLSearchParams()

// console.log(params.get(`id`))
  list()

  $(`.left_con`).on(`click`,`a`,function(){
    window.location.href=`./article.html?id=${$(this).attr(`data-id`)}`
})
    // one---one
    $(`.menu`).on(`click`,`a`,function(){
        objs.type= $(this).attr(`data-id`)
        list()
    })
    $(`.search_btn`).on(`click`,function(){
       objs.key=$(`.search_txt`).val()
       list()
    })
    // two----
    $.ajax({
        url:"index/rank",
        type:"get",
        success:function(res){
            // console.log(res)
            let temp=template(`two`,res)
            $(`.nima`).html(temp)
        }
    })
    $(`.nima`).on(`click`,`a`,function(){
        window.location.href=`./article.html?id=${$(this).attr(`data-id`)}`
    })
    // twos---
    $.ajax({
        url:"index/attention",
        type:"get",
        success:function(res){
            console.log(res)
            let temps=template(`twos`,res)
            $(`.guanzhu_list`).html(temps)
        }
    })
    // $(`.guanzhu_list`).on(`click`,`a`,function(){
    //     window.location.href=`./article.html?id=${$(this).attr(`data-id`)}`
    // })
    // theer--
    $.ajax({
        url:"index/latest_comment",
        type:"get",
        success:function(res){
            console.log(res)
            let temps=template(`theer`,res)
            $(`.comment_list`).html(temps)
        }
    })
    // four----
    $.ajax({
        url:"index/category",
        type:"get",
        success:function(res){
console.log(res)
let temps=template(`four`,res)
$(`.level_two,.left_menu`).append(temps)
        }
    })
   
})